package com.tjsinfo.tjsoa.useseal.bo;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.tjsinfo.tjsoa.Dao.IQbcDao;
import com.tjsinfo.tjsoa.common.ToolKit;
import com.tjsinfo.tjsoa.useseal.dao.ITUseSealSealDAO;
import com.tjsinfo.tjsoa.useseal.vo.TUseSealSeal;

public class TUseSealSealBO implements ITUseSealSealBO {
	
	private IQbcDao qbcDao;
	private ITUseSealSealDAO sealDao;
	
	
	public void setQbcDao(IQbcDao qbcDao) {
		this.qbcDao = qbcDao;
	}

	public void setSealDao(ITUseSealSealDAO sealDao) {
		this.sealDao = sealDao;
	}

	public void save(TUseSealSeal transientInstance) {
		// TODO Auto-generated method stub
		sealDao.save(transientInstance);
	}

	public List<TUseSealSeal> selectAll(Integer first, Integer max,Integer sealMark,HttpServletRequest request) {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TUseSealSeal.class);
		detachedCriteria.add(Restrictions.eq("applyId", String.valueOf(ToolKit.getSessionUser(request).getUser_id())));
		detachedCriteria.add(Restrictions.eq("mark", sealMark));
		List<Order> orderlist= new ArrayList<Order>();
		orderlist.add(Order.desc("dateTime"));
		return qbcDao.findPageByCriteria(detachedCriteria, orderlist, max, first).getItems();
	}	
	
	public List<TUseSealSeal> selectColumn(Integer first, Integer max,Integer sealMark,String column,String columnName,HttpServletRequest request) {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TUseSealSeal.class);
		detachedCriteria.add(Restrictions.eq("applyId", String.valueOf(ToolKit.getSessionUser(request).getUser_id())));
		detachedCriteria.add(Restrictions.eq("mark", sealMark));
		detachedCriteria.add(Restrictions.eq(column,columnName));
		List<Order> orderlist= new ArrayList<Order>();
		orderlist.add(Order.desc("dateTime"));
		return qbcDao.findPageByCriteria(detachedCriteria, orderlist, max, first).getItems();
	}		
	
	public Integer selectTotal() {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TUseSealSeal.class);
		
		return  qbcDao.getQueryNumber(detachedCriteria, "id");
	}

	public List<TUseSealSeal> cheakOverAll(Integer sealMark,HttpServletRequest request) {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TUseSealSeal.class);
		detachedCriteria.add(Restrictions.like("userId", "%" + ToolKit.getSessionUser(request).getUser_id() + "%"));
		detachedCriteria.add(Restrictions.eq("mark", sealMark));
		detachedCriteria.addOrder(Order.desc("dateTime"));
		return qbcDao.getCriteria(detachedCriteria);
	}	
	
	public List<TUseSealSeal> cheakOverColumn(Integer sealMark,String column,String columnName,HttpServletRequest request) {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TUseSealSeal.class);
		detachedCriteria.add(Restrictions.like("userId", "%" + ToolKit.getSessionUser(request).getUser_id() + "%"));
		detachedCriteria.add(Restrictions.eq("mark", sealMark));
		detachedCriteria.add(Restrictions.eq(column,columnName));
		detachedCriteria.addOrder(Order.desc("dateTime"));
		return qbcDao.getCriteria(detachedCriteria);
	}	
	
	public Integer cheakOverTotal() {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TUseSealSeal.class);
		
		return  qbcDao.getQueryNumber(detachedCriteria, "id");
	}	
	
	public List findByExample(TUseSealSeal instance) {
		// TODO Auto-generated method stub
		return sealDao.findByExample(instance);
	}

	public TUseSealSeal findById(String id) {
		// TODO Auto-generated method stub
		return sealDao.findById(id);
	}

	public void update(TUseSealSeal transientInstance) {
		// TODO Auto-generated method stub
		sealDao.update(transientInstance);
	}

	public void delete(String id) {
		// TODO Auto-generated method stub
		sealDao.delete(id);
	}

	public String saveId(TUseSealSeal transientInstance) {
		// TODO Auto-generated method stub
		return sealDao.saveId(transientInstance);
	}	
}
